package com.gorkr.bio.multi_thread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author gorkr
 * @date 2022/05/31 00:14
 **/
public class ServerThreadReader extends Thread{
    private Socket socket;

    ServerThreadReader(Socket socket){
        this.socket = socket;
    }


    // 每一个线程获取socket后进行的任务处理
    @Override
    public void run() {
        try {
            // 字节输入流
            InputStream is = socket.getInputStream();
            // 使用缓存字符输入流包装字节输入流
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String msg;
            while ((msg = br.readLine()) != null){
                System.out.println(msg);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
    